/**
* @file drv_ctp.h
* @brief  ctp driver
* @details 
* @author huangbin
* @version V1.0.0
* @date 2025-05-10
* @copyright All documents are copyrighted by Shenzhen Xinlongwei Technology Co., LTD.
*            They may not be used for commercial purposes without permission
*/
#ifndef __DRV_CTP_H__
#define	__DRV_CTP_H__
#include "inc.h"

#ifdef __cplusplus
 extern "C" {
#endif /* __cplusplus */
////////////////////////////////////////////////////////////

#define TP_RESET_PORT_CLK        RCC_APB2Periph_GPIOC
#define TP_RESET_PORT GPIOC
#define TP_RESET_PIN  GPIO_Pin_13

#define TP_INT_PORT_CLK        RCC_APB2Periph_GPIOB
#define TP_INT_PORT GPIOB
#define TP_INT_PIN  GPIO_Pin_7

#define TP_RESET_HIGH()		GPIO_SetBits(TP_RESET_PORT, TP_RESET_PIN)
#define	TP_RESET_LOW()		GPIO_ResetBits(TP_RESET_PORT, TP_RESET_PIN)

#define TP_INT_HIGH()		GPIO_SetBits(TP_INT_PORT, TP_INT_PIN)
#define	TP_INT_LOW()		GPIO_ResetBits(TP_INT_PORT, TP_INT_PIN)

/**
* @brief 手势识别 
* @details 定义标准手势识别宏
*/       
typedef enum
{
	GES_TYPE_NONE			= 0x00,
	GES_TYPE_UP				= 0x01,	//TP手势：向上滑动
	GES_TYPE_DOWN			= 0x02,	//TP手势：向下滑动
	GES_TYPE_LEFT			= 0x03,	//TP手势：向左滑动
	GES_TYPE_RIGHT			= 0x04,	//TP手势：向右滑动
	GES_TYPE_CLICK    		= 0x05,	//TP单击
	GES_TYPE_DOUBLE_CLICK	= 0x0b,	//双击
	GES_TYPE_PRESS			= 0x0c,  //长按
}GES_Typedef;

#define INVALID_COOR 0xFFFF	//无效坐标

#define	MOUSE_UP	0
#define	MOUSE_DOWN	1
#define	MOUSE_MOVE	2

typedef	struct tagMouse {
	uint16_t x, y;
	uint8_t  Status;	//前一个时刻手指状态
	GES_Typedef	 Gesture;
}Mouse_Typedef; 

#define SET_MOUSE_COOR(x,y)			((y << 16) | x)
#define GET_MOUSE_X(lParam)			(lParam & 0x0000FFFF)
#define GET_MOUSE_Y(lParam)			((lParam >> 16) & 0x0000FFFF)
/*!
 * \brief tp scan
 * \return tp coordinate
 */
extern uint32_t tp_get_data(void);
/*!
 * \brief tp reset
 */
extern void tp_Reset(void);
/*!
 * \brief tp initialize
 */
extern void tp_Init(void);

//CST328的地址
#define TP_IIC_SLAVE_ADDR_CST328  (0x1A<<1) //write addr 0x34,read 0x35

//CST816D的地址
#define TP_IIC_SLAVE_ADDR_CST816D  (0x15<<1)

//FT6336U的地址
#define TP_IIC_SLAVE_ADDR_FT6336U  (0x38<<1)

//GT911的地址:0xBA/0xBB(int=0)
//GT911的地址:0x28/0x29(int=1)
#define TP_IIC_SLAVE_ADDR_GT911  (0xBA)

#define CTP_TYPE_GT911		0
#define CTP_TYPE_CST816		1
#define CTP_TYPE_FT6336U	2
#define CTP_TYPE_CST328		3

#define CTP_TYPE	CTP_TYPE_CST328	//tp type
//////////////////////////////////////////////////////////////////////////

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif 

